<%-- 
    Document   : cadastroHospede
    Created on : 02/11/2014, 18:05:46
    Author     : Milena
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
        <%@include file="top.html" %>
        <div id="titulo" align="center">
            <h2>Cadastre-se!</h2>
        </div>
        <div id="legenda">
            Cadastre-se e fique por dentro de nossas notícias e promoções.
        </div>
        <br>
        <table align="center" width="500px" border="1px">
            <tr>
                <td>
                    <form class="form-horizontal" name="cadastro" action="gerencia" method="POST">
                        <fieldset>
                            <div id="conteudo" style="margin-top:15px; margin-bottom:15px; margin-left:15px; margin-right:15px;">
                                <legend>Dados Pessoais</legend>
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="nome">Nome: </label>  
                                    <div class="col-md-7">
                                        <input id="nome" name="nome" type="text" placeholder="" class="form-control input-md">
                                        <span class="help-block">Digite seu nome completo.</span>  
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-4 control-label"  for="sexo">Sexo:</label>
                                    <div class="col-md-4">
                                        <div class="radio">
                                            <label for="sexo-0">
                                                <input type="radio" name="sexo" id="sexo" value="f" checked="checked">
                                                Feminino
                                            </label>
                                        </div>
                                        <div class="radio">
                                            <label for="sexo-1">
                                                <input type="radio" name="sexo" id="sexo" value="m">
                                                Masculino
                                            </label>
                                        </div>
                                    </div>
                                </div>                     
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="cpf">CPF: </label>  
                                    <div class="col-md-4">
                                        <input id="cpf" name="cpf" type="text" placeholder="" class="form-control input-md">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="email">Email: </label>  
                                    <div class="col-md-6">
                                        <input id="email" name="email" type="text" placeholder="" class="form-control input-md">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="senha">Senha:</label>
                                    <div class="col-md-4">
                                      <input id="senha" name="senha" type="password" placeholder="" class="form-control input-md">
                                      <span class="help-block">A senha deve conter letras e números.</span>
                                    </div>
                                </div>
                                <input type="hidden" id="req" name="req" value="cadastro">
                                <div align='center'>
                                    <input type="button" value="Cadastrar" class="btn btn-success" onclick="valida();">
                                    <input type="button" value="Cancelar" class="btn btn-danger" onclick="cancela();">
                                </div>
                            </div>
                            <div id="respostaServidor">nnnnn</div>
                        </fieldset>
                    </form>
                </td>
            </tr>
        </table>
        <br>
        <%@include file="footer.html" %>
        <script type="text/javascript">
            
            function iniciaAjax() {
                var objetoAjax = false;
                if (window.XMLHttpRequest) {
                    objetoAjax = new XMLHttpRequest();
                } else if (window.ActiveXObject) {
                    try {
                        objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch(e) {
                        try {
                            objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch(ex) {
                            objetoAjax = false;
                        }
                    }
                }
                return objetoAjax;
            }
            
    var ini = iniciaAjax();
    
            function valida(){
                
                var nome = document.getElementById("nome").value;
                 var req = document.getElementById("req").value;
                var cpf = document.getElementById("cpf").value;
                var sexo = document.getElementById("sexo").value;
                var email = document.getElementById("email").value;
                var senha = document.getElementById("senha").value;
                
                var url = "http://localhost:8083/Hotel_SDI/hospede?nome="+nome+"&cpf="+cpf+"&sexo="+sexo+"&email="+email+"&senha="+senha+"&req="+req;
               // var url = "http://localhost:8080/Hotel_SDI/gerencia?nome="+nome+"&nascimento="+nascimento;
                ini.open("GET",url,true);
                ini.onreadystatechange = callback;
                ini.send(null);   
            }
            
              function callback(){
                if (ini.readyState === 4){
                    if (ini.status === 200){ 
                        document.getElementById("respostaServidor").innerHTML = ini.responseText;                    
                    }
                }
            }
            
            function cancela(){
                if (confirm("Deseja cancelar o cadastro e voltar para a página inicial?") === true) {
                    window.location = "http://localhost:27491/Hotel_SDI/index.html";
                }
            }
            
        </script>